/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package landinggearsystem;

import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

/**
 *
 * @author Valentin
 */
public class Interface extends JFrame{
    
    Dimension dimension = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    int height = (int) dimension.getHeight();//obtenir hauteur écran
    int width = (int) dimension.getWidth();//obtenir largeur écran
    
    JLabel LedRouge = new JLabel();
    JLabel LedOrange = new JLabel();
    JLabel LedVert = new JLabel();
    JLabel EtatRoue = new JLabel();
    
    Software s;
    
    
    
    Interface(int largeur, int hauteur, Software soft){
        
        s=soft;
        
        setLocation((width - largeur) / 2, (height - hauteur) / 2);//centrer fenetre
        setSize(largeur, hauteur);
        setResizable(false);//taille fixe
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//fermer le programme
        setVisible(true);
        String titre = "Landing Gear System";
        setTitle(titre);
        
        Container ContentPane = this.getContentPane();
        ContentPane.setBackground(Color.WHITE);
        
        JLabel fond = new JLabel();
        
        JButton boutonLever = new JButton("Lever");
        boutonLever.setBounds(new Rectangle(10,10, 100,50));
        boutonLever.addMouseListener(new Lever());
        
        JButton boutonBaisser = new JButton("Baisser");
        boutonBaisser.setBounds(new Rectangle(10,70, 100,50));
        boutonBaisser.addMouseListener(new Baisser());
        
        
        
        LedRouge.setBounds(new Rectangle(150, 15, 20, 20));
        LedRouge.setBackground(Color.BLACK);
        LedRouge.setOpaque(true);
        LedRouge.setVisible(true);
        
        
        LedOrange.setBounds(new Rectangle(150, 55, 20, 20));
        LedOrange.setBackground(Color.BLACK);
        LedOrange.setOpaque(true);
        LedOrange.setVisible(true);
        
        
        LedVert.setBounds(new Rectangle(150, 95, 20, 20));
        LedVert.setBackground(Color.BLACK);
        LedVert.setOpaque(true);
        LedVert.setVisible(true);
        
        EtatRoue.setBounds(new Rectangle(200, 40, 100, 50));
        EtatRoue.setText("Etat de la roue");
    //    EtatRoue.setOpaque(true);
        EtatRoue.setVisible(true);
        
        ContentPane.add(EtatRoue);
        ContentPane.add(LedVert);
        ContentPane.add(LedOrange);
        ContentPane.add(LedRouge);
        ContentPane.add(boutonLever);
        ContentPane.add(boutonBaisser);
        ContentPane.add(fond);//affichage fond
        
        this.revalidate();//éviter bug affichage
    }

    
    
    public void LedRouge()
    {
       EteindreLed();
       LedRouge.setBackground(Color.RED);
    }
    
    public void LedOrange()
    {
       EteindreLed();
       LedOrange.setBackground(Color.ORANGE);
    }
    
    public void LedVert()
    {
       EteindreLed();
       LedVert.setBackground(Color.GREEN);
    }
    
    
    
    public void EteindreLed()
    {
       LedRouge.setBackground(Color.BLACK);
       LedOrange.setBackground(Color.BLACK);
       LedVert.setBackground(Color.BLACK);
    }
    
    
    public void RoueLevee()
    {
        EtatRoue.setText("Roue levée");
    }
    
    public void RoueBaissee()
    {
        EtatRoue.setText("Roue baissée");
    }
    
    public void RoueMouvement()
    {
        System.out.println("MOUVEMENT........................................................................");
        EtatRoue.setText("TEST");
        System.out.println("MOUVEMENT/////////////////////////////////////////////////////////////////////////");
    }

    private class Lever implements MouseListener {

        public Lever() {
        }

        @Override
        public void mouseClicked(MouseEvent me) {
        s.leverLevier();
        }

        @Override
        public void mousePressed(MouseEvent me) {
         }

        @Override
        public void mouseReleased(MouseEvent me) {
         }

        @Override
        public void mouseEntered(MouseEvent me) {
        }

        @Override
        public void mouseExited(MouseEvent me) {
        }
    }

    private class Baisser implements MouseListener {

        public Baisser() {
        }

        @Override
        public void mouseClicked(MouseEvent me) {
        s.baisserLevier();
        }

        @Override
        public void mousePressed(MouseEvent me) {
          }

        @Override
        public void mouseReleased(MouseEvent me) {
          }

        @Override
        public void mouseEntered(MouseEvent me) {
        }

        @Override
        public void mouseExited(MouseEvent me) {
        }
    }
    
}
